<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, width=device-width">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta content="black" name="apple-mobile-web-app-status-bar-style">
	<meta name="format-detection" content="telephone=no">
	<meta content="telephone=no" name="format-detection">
	<meta http-equiv="X-UA-Compatible" content="chrome=1,IE=edge" />
	<link href="http://www.runoob.com/try/bootstrap/twitter-bootstrap-v2/docs/assets/css/bootstrap.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet" media="screen and (max-width:900px)" href="/assets/stylesheets/style_wap.css" type="text/css" />
	<link rel="stylesheet" media="screen and (min-width:900px)" href="/assets/stylesheets/style_pc.css" type="text/css" />
	<title>转账给其他用户</title>
</head>
<body>
	<!-- 前端嵌套写法，仅供前端使用，首页有完整代码 -->
	<div class="topline" id="J_topline" data-til="现金积分转账给其他用户">
		<nav th:replace="hjh/include::menuV"></nav>
	</div>

	<div class="vipreg content">
		<p class="fgtil">转账给其他用户</p>
		<div class="formline" >
			<div class="fline"><p class="ado">用户名：</p><p class="flinete" th:text="${session.user.username}">Np2847</p></div>
			<div id="div_insert_point" class="fline"><p class="ado">转入用户：</p><div class="clearfix">
			<input class="J_ctrol ctrol" type="text" autocomplete="off" placeholder="请输入转入用户的会员名" name="" id="J_other"></div></div>

			<div class="fline"><p class="ado">用户真实姓名：</p><input class="J_ctrol ctrol" data-target="realname" type="text" placeholder="转入用户的真实姓名" name="" id="J_realname"></div>

			<div class="fline">
				<p class="ado">转移额度：</p>
				<input class="J_ctrol ctrol" data-target="edu" data-type="number" type="text" placeholder="" name="" id="J_edu">
				<br />必须是整数
			</div>
			<div class="fline"><p class="ado">交易密码：</p><input class="J_ctrol ctrol" data-target="edu" type="password" placeholder="" name="" id="J_payPwd">
			</div>
			<div class="fline linea"><a href="javascript:;" class="btn fbtm" id="J_btn">提交</a></div>

		</div>
	</div>
	<nav th:replace="hjh/include::bottomV"></nav>
	<script language="javascript" type="text/javascript" src="/assets/javascript/jquery-2.1.4.min.js"></script>
	<script language="javascript" type="text/javascript" src="/assets/javascript/func.js"></script>
	<script language="javascript" type="text/javascript" src="/assets/javascript/bootstrap-typeahead.js"></script>
	<script type="text/javascript">
		$(function(){
            $.fn.typeahead.Constructor.prototype.blur = function () {
                var that = this;
                setTimeout(function () { that.hide() }, 250);
            };
		    $("#J_other").typeahead({
				insertPoint:$("#J_other"),
                source: function (query, process) {
                    $.get('/search_user?keyword='+query,"",function (data) {
                        process(data);
                    })
                }
            });

			$('.J_ctrol').blur(function(){
				var self = $(this),
					val = self.val().trim(),
					type = self.attr('data-type')||'text',
					tar = self.attr('data-target');

				if(type=="number"){
					var regnum = /^[0-9]{1,}$/ig;
			        if(!regnum.test(val)){
			            return;
			        };
				};
				if(val){
					self.val(val);
					data[tar] = val; // 数据填充
				};
			});

			var J_btn = $('#J_btn'),
				isajax = false, // 设置开关
				data = {"taocan":1,"vip":1};


			J_btn.click(function(){
				if(isajax){return false;}

				data.other = $("#J_other").val();
				data.realname = $("#J_realname").val();
				data.edu = $('#J_edu').val();
                data.payPwd = $("#J_payPwd").val();

				if(!data.other){
					errormsg($('#J_other'),'请输入转入用户的会员名');
					return;
				};
				if(!data.realname){
					errormsg($('#J_realname'),'请输入真实姓名');
					return;
				};
				if(!data.edu){
					errormsg($('#J_edu'),'请输入转移额度');
					return;
				};
                if(!data.payPwd){
                    errormsg($('#J_payPwd'),'请输入交易密码');
                    return;
                };

				//ajax提交数据
				isajax = true;
				J_btn.html("正在提交···");
				$.ajax({
					type: "POST",
					url: "/cash_transfer?v="+(new Date().getTime()),
					data: JSON.stringify(data),
					contentType:"application/json",
					dataType: "json",
					success: function(res){
						if(res.code==0){
							// 提交成功
							alert('提交成功');
							window.location.href = "/cash_points_list"
						}else if(res.code==101){
                            errormsg($('#J_other'),res.msg);
						}else if(res.code==102){
                            errormsg($('#J_realname'),res.msg);
						}else if(res.code == 103){
                            errormsg($('#J_edu'),res.msg);
						}else if(res.code == 104){
                            errormsg($('#J_payPwd'),res.msg);
						}
					},
					complete:function(){
						isajax = false;
					}
				});

			});
		});


		$(document).ready(function(){
		    var ipt = $('#J_edu');
		    ipt.on('keyup',function(){
		        if(! /^\d+$/.test(this.value)){
		            this.value='';
		        }
		    })
		});

	</script>
</body>
</html>
